<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">^Lorem| <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">^Lorem |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-0 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">L|orem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">L^orem| <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">L^orem |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-1 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lo|rem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lo^rem| <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lo^rem |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-2 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lor|em <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lor^em| <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lor^em |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-3 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lore|m <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lore^m| <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lore^m |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-4 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem| <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem^ <span style="direction: ltr">ipsum| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem^ |<span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-5 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">|ipsum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">^ipsum| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">^ipsum |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-6 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">i|psum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">i^psum| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">i^psum |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-7 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ip|sum dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ip^sum| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ip^sum |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-8 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ips|um dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ips^um| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ips^um |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-9 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsu|m dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsu^m| dolor<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsu^m |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-10 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum| dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum^ dolor|<div> just a test</div> sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum^ |dolor<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-11 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum |dolor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum ^dolor|<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-12 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum d|olor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum d^olor|<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-13 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum do|lor<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum do^lor|<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-14 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dol|or<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dol^or|<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-15 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolo|r<div > just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolo^r|<div> just a test</div> sit</span> amet</div>',
  `${behavior} 7-16 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div >| just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor|<div>^ just a test</div> sit</span> amet</div>',
  `${behavior} 7-17 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > |just a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor|<div>^ just a test</div> sit</span> amet</div>',
  `${behavior} 7-18 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > j|ust a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> |j^ust a test</div> sit</span> amet</div>',
  `${behavior} 7-19 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > ju|st a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> |ju^st a test</div> sit</span> amet</div>',
  `${behavior} 7-20 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > jus|t a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> |jus^t a test</div> sit</span> amet</div>',
  `${behavior} 7-21 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just| a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> |just^ a test</div> sit</span> amet</div>',
  `${behavior} 7-22 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just |a test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> |just ^a test</div> sit</span> amet</div>',
  `${behavior} 7-23 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a| test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just |a^ test</div> sit</span> amet</div>',
  `${behavior} 7-24 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a |test</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just |a ^test</div> sit</span> amet</div>',
  `${behavior} 7-25 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a t|est</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a |t^est</div> sit</span> amet</div>',
  `${behavior} 7-26 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a te|st</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a |te^st</div> sit</span> amet</div>',
  `${behavior} 7-27 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a tes|t</div> sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a |tes^t</div> sit</span> amet</div>',
  `${behavior} 7-28 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div>| sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> ^sit|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> ^sit</span> |amet</div>',
  `${behavior} 7-29 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> |sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> ^sit|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> ^sit</span> |amet</div>',
  `${behavior} 7-30 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> s|it</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> s^it|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> s^it</span> |amet</div>',
  `${behavior} 7-31 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> si|t</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> si^t|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> si^t</span> |amet</div>',
  `${behavior} 7-32 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span>| amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span>^ amet|</div>'
      : '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span>^ |amet</div>',
  `${behavior} 7-33 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> |amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> ^amet|</div>',
  `${behavior} 7-34 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> a|met</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> a^met|</div>',
  `${behavior} 7-35 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> am|et</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> am^et|</div>',
  `${behavior} 7-36 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> ame|t</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> ame^t|</div>',
  `${behavior} 7-37 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div > just a test</div> sit</span> amet|</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: ltr">ipsum dolor<div> just a test</div> sit</span> amet|</div>',
  `${behavior} 7-38 rtl left word`);
}
</script>
